package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzParam;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    // 分页查询
    @GetMapping("/clazzs")
    public Result selectClazzDatas(ClazzParam clazzParam) {
        PageBean pageBean = clazzService.selectClazzDatas(clazzParam);
        return Result.success(pageBean);

    }

//     删除
    @DeleteMapping("/clazzs/{id}")
    public Result delClazzById(@PathVariable Integer id) throws Exception {
        System.out.println("id0000 = " + id);
        clazzService.delClazzById(id);
        return Result.success();
    }

//     1，新增班级：
    @PostMapping("/clazzs")
    public Result insertClass(@RequestBody Clazz clazz){
        clazzService.insertClass(clazz);
        return Result.success();
    }

//     修改班级时的数据回显
    @GetMapping("/clazzs/{id}")
    public Result getClazzById(@PathVariable Integer id){

       Clazz clazz = clazzService.getClazzById(id);
       return Result.success(clazz);
    }
//     修改 班级内容
    @PutMapping("/clazzs")
    public Result updateClass(@RequestBody Clazz clazz){

        clazzService.updateClass(clazz);

        return Result.success();

    }

    // 获取所有班级的信息  clazzs/list

    @GetMapping("/clazzs/list")
    public Result getAllClazzInfo(){
      List<Clazz> list = clazzService.getAllClazzInfo();
      return Result.success(list);
    }





}
